package com.binary.coder.gift.core.common.bean;

import java.util.HashMap;
import java.util.Map;


/**
 * @author weitao
 */
public class ResultBean<DATA>{

    public static Short CODE_SUCCESS = 0;
    public static Short CODE_FAIL = -1;

    /**
     * 未登陆，请求要求身份验证
      */
    public static Short CODE_NO_AUTH = 401;
    /**
     * 已登录，但没有权限
     */
    public static Short CODE_NO_PERMISSION = 403;


    /**
     * 状态
     */
    private int code = CODE_SUCCESS;
    /**
     * 消息
     */
    private String message;
    /**
     * 数据
     */
    private DATA data;

    private ResultBean() {
    }

    private ResultBean(DATA data, String message, int code) {
        this.data = data;
        this.message = message;
        this.code = code;
    }

    private ResultBean(String message, int code) {
        this.message = message;
        this.code = code;
    }

    private ResultBean(DATA data, int code) {
        this.data = data;
        this.code = code;
    }

    private ResultBean(DATA data) {
        this.data = data;
    }

    private ResultBean(String message) {
        this.message = message;
    }

    public ResultBean(DATA data, String message) {
        this.data = data;
        this.message = message;
    }



    public static <DATA> ResultBean<DATA> create(DATA data) {
        return new ResultBean<>(data);
    }

    public static <DATA> ResultBean<DATA> create(DATA data, int code) {
        return new ResultBean<>(data, code);
    }

    public static <DATA> ResultBean<DATA> create(String msg, int code) {
        return new ResultBean<>(msg, code);
    }

    public static <DATA> ResultBean<DATA> create(DATA data, String msg, int code) {
        return new ResultBean<>(data, msg, code);
    }

    public static <DATA> ResultBean<DATA> create(String msg) {
        return new ResultBean<>(msg);
    }

    public static <DATA> ResultBean<DATA> create(DATA data, String msg) {
        return new ResultBean<>(data, msg);
    }

    public static <DATA> ResultBean<DATA> create() {
        return new ResultBean<>();
    }




    public static ResultBean success() {
        return ResultBean.create("成功", ResultBean.CODE_SUCCESS);
    }

    public static ResultBean success(int code) {
        return ResultBean.create("成功", code);
    }


    public static <DATA> ResultBean<DATA> success(String message) {
        return ResultBean.create(null, message, ResultBean.CODE_SUCCESS);
    }


    public static <DATA> ResultBean<DATA> success(String message, int code) {
        return ResultBean.create(null, message, code);
    }

    public static <DATA> ResultBean<DATA> success(DATA data) {
        return ResultBean.create(data, "成功", ResultBean.CODE_SUCCESS);
    }

    public static <DATA> ResultBean<DATA> success(DATA data, String message) {
        return ResultBean.create(data, message, ResultBean.CODE_SUCCESS);
    }


    public static ResultBean failed() {
        return ResultBean.create("失败", ResultBean.CODE_FAIL);
    }

    public static ResultBean failed(int code) {
        return ResultBean.create("失败", code);
    }

    public static <DATA> ResultBean<DATA> failed(String message) {
        return ResultBean.create(null, message, ResultBean.CODE_FAIL);
    }

    public static <DATA> ResultBean<DATA> failed(String message, int code) {
        return ResultBean.create(null, message, code);
    }


    public static <DATA> ResultBean<DATA> failed(DATA data) {
        return ResultBean.create(data, "成功", ResultBean.CODE_FAIL);
    }

    public static <DATA> ResultBean<DATA> failed(DATA data, String message) {
        return ResultBean.create(data, message, ResultBean.CODE_FAIL);
    }


    public static <DATA> ResultBean<DATA> failed(DATA data, String message, int code) {
        return ResultBean.create(data, message, code);
    }


    public int getCode() {
        return code;
    }

    public ResultBean<DATA> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResultBean<DATA> setMessage(String message) {
        this.message = message;
        return this;
    }

    public DATA getData() {
        return data;
    }

    public ResultBean<DATA> setData(DATA data) {
        this.data = data;
        return this;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", getData());
        map.put("code", getCode());
        map.put("message", getMessage());
        return map;
    }

}
